package com.csh.subject.common.enums;

import lombok.Getter;

@Getter
public enum ResultCodeEnum {
    //枚举类的对象名称，定义多少个就有多少个对象
    SUCCESS(200,"操作成功"),
    FAIL(500,"操作失败");

    private int code;
    private String msg;

    ResultCodeEnum(int code , String msg){
        this.code = code;
        this.msg = msg;
    }

    //当调用 ResultCodeEnum.values() 方法时，会返回一个包含所有枚举常量的数组,在这个数组中，SUCCESS 和 FAIL 会依次排列
    //for(ResultCodeEnum resultCodeEnum : ResultCodeEnum.values()) 循环遍历这个数组，对每个枚举常量执行相应的操作
    public static ResultCodeEnum getByCode(int codeValue){
        for(ResultCodeEnum resultCodeEnum : ResultCodeEnum.values()){
            if (resultCodeEnum.code == codeValue){
                return resultCodeEnum;
            }
        }
        return null;
    }
}
